//
//  PayViewController.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/11/23.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class PayViewController: KMViewController {
    
    var showTabBar : (()->())? //显示底部标签栏
    var payBlock : (()->())? //已还清

    override func viewDidLoad() {
        super.viewDidLoad()

        addSubView()
    }
    
    //MARK: 添加子视图
    fileprivate func addSubView() {
        
        let payView = PayView.init(frame: self.view.bounds)
        payView.delegate = self
        payView.arrowButton.addTarget(self, action: #selector(cancelRepayment), for: .touchUpInside)
        payView.payButton.addTarget(self, action: #selector(repaymentedAction), for: .touchUpInside)
        self.view.addSubview(payView)
        
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        
        self.showTabBar!()
        self.dismiss(animated: false, completion: nil)
    }
    
    //MARK: 取消还款
    @objc fileprivate func cancelRepayment() {
        
        self.showTabBar!()
        self.dismiss(animated: false, completion: nil)
    }
    
    //MARK: 已还清
    @objc fileprivate func repaymentedAction() {
        
        self.showTabBar!()
        self.payBlock!()
        self.dismiss(animated: false, completion: nil)
    }

    
}

extension PayViewController : PayViewDelegate {
    
    //MARK: 选择还款方式
    func selectRepaymentType(index: Int) {
        
        switch index {
        case 0://支付宝
            UIApplication.shared.openURL(URL.init(string: "alipay://")!)
        case 1://微信
           UIApplication.shared.openURL(URL.init(string: "weixin://")!)
        default:
            break
        }
    }
}
